<?php

declare(strict_types=1);

namespace app\api\controller\v1;
use app\common\Frontend;
use Throwable;
use app\common\model\Invoice;

class InvoiceCon extends Frontend
{

    protected array $noNeedLogin = [];

    protected $model;
    protected $price;
    public function initialize(): void
    {
        parent::initialize();
        $this->model = new Invoice();
    }



    //发票申请
    public function applyInvoice(){
        if ($this->request->isPost()) {
            $data = $this->request->param('ruleForm');
            if (!$data) {
                $this->error('参数不能为空');
            }
            $data['user_id'] = $this->auth->id;
            $result = false;
            $this->model->startTrans();
            try {
                $result = $this->model->save($data);
                $this->model->commit();
            } catch (Throwable $e) {
                $this->model->rollback();
                $this->error($e->getMessage());
            }
            if ($result !== false) {
                $this->success('创建成功1');
            } else {
                $this->error(('未添加任何行'));
            }
        }
        $this->error(('参数错误'));
    }
}